package datalookin.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.whu.zj.MyApplication;
import com.whu.zj.R;

import java.util.ArrayList;
import java.util.List;

import datalookin.dto.StationAllDataDto;

/**
 * 监测数据
 * Created by Administrator on 2016/3/5.
 */
public class MonitorAdapter extends BaseAdapter {

    List<StationAllDataDto> stationAllDataDtos = new ArrayList<StationAllDataDto>();

    public void setStationAllDataDtos(List<StationAllDataDto> stationAllDataDtos) {
        this.stationAllDataDtos = stationAllDataDtos;
    }

    @Override
    public int getCount() {
        return stationAllDataDtos.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            viewHolder = new ViewHolder();
            convertView = View.inflate(MyApplication.share(), R.layout.item_realinfo,null);
            viewHolder.tv_pressure = (TextView) convertView.findViewById(R.id.id_tv_pressure);
            viewHolder.tv_chlorine = (TextView) convertView.findViewById(R.id.id_tv_chlorine);
            viewHolder.tv_flow = (TextView) convertView.findViewById(R.id.id_tv_flow);
            viewHolder.tv_turbidity = (TextView) convertView.findViewById(R.id.id_tv_turbidity);
            viewHolder.tv_loc = (TextView) convertView.findViewById(R.id.id_tv_loc);
            convertView.setTag(viewHolder);
        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        StationAllDataDto stationAllDataDto = stationAllDataDtos.get(position);
        viewHolder.tv_pressure.setText(stationAllDataDto.getPressureValue()==null?"无":stationAllDataDto.getPressureValue());
        viewHolder.tv_turbidity.setText(stationAllDataDto.getTurbidityValue()==null?"无":stationAllDataDto.getTurbidityValue());
        viewHolder.tv_flow.setText(stationAllDataDto.getFlowValue()==null?"无":stationAllDataDto.getFlowValue());
        viewHolder.tv_chlorine.setText(stationAllDataDto.getChlorineValue()==null?"无":stationAllDataDto.getChlorineValue());
        viewHolder.tv_loc.setText(stationAllDataDto.getStationnum());
        return convertView;
    }

    public static class ViewHolder
    {
        public TextView tv_pressure;
        public TextView tv_chlorine;
        public TextView tv_turbidity;
        public TextView tv_flow;
        public TextView tv_loc;
    }
}
